//
//  TabBarViewController.m
//  MapEXPO
//
//  Created by 洪雯 on 16/4/2.
//  Copyright © 2016年 洪雯. All rights reserved.
//

#import "TabBarViewController.h"
#import "HomeViewController.h" //主页
#import "RouteViewController.h"//路线
#import "MapViewController.h" //地图
#import "TravelNotesViewController.h"//游记
#import "MyselfViewController.h"//我的
#import "NavigationViewController.h"
#import "TabBar.h"

@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //主页
    HomeViewController *home = [[HomeViewController alloc]init];
    [self addChildViewController:home image:@"tabbar_home" selectedImage:@"tabbar_home_selected" title:@"首页"];
    
    //路线
    RouteViewController *message = [[RouteViewController alloc]init];
    [self addChildViewController:message image:@"tabbar_message_center" selectedImage:@"tabbar_message_center_selected" title:@"路线"];
    
    //游记
    TravelNotesViewController *discover = [[TravelNotesViewController alloc]init];
    [self addChildViewController:discover image:@"tabbar_discover" selectedImage:@"tabbar_discover_selected" title:@"游记"];
    
    //我的
    MyselfViewController *profile = [[MyselfViewController alloc]init];
    [self addChildViewController:profile image:@"tabbar_profile" selectedImage:@"tabbar_profile_selected" title:@"我的"];
    
    //tabBar
    TabBar *tabBar = [[TabBar alloc]init];
    [self setValue:tabBar forKeyPath:@"tabBar"];
    

}

/**
 *  添加子控制器
 *
 *  @param childViewController 子控制器
 *  @param image               tabBarItem正常状态图片
 *  @param selectedImage       tabBarItem选中状态图片
 *  @param title               标题
 */
- (void)addChildViewController:(UIViewController *)childViewController image:(NSString *)image selectedImage:(NSString *)selectedImage title:(NSString *)title {
    
    //标题
    childViewController.title = title;
    childViewController.view.backgroundColor = [UIColor whiteColor];
    
    //tabBarItem图片
    childViewController.tabBarItem.image = [UIImage imageNamed:image];
    childViewController.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //tabBarItem字体的设置
    //正常状态
    NSMutableDictionary *normalText = [NSMutableDictionary dictionary];
    normalText[NSForegroundColorAttributeName] = [UIColor colorWithRed:123/255.0 green:123/255.0 blue:123/255.0 alpha:1.0];
    [childViewController.tabBarItem setTitleTextAttributes:normalText forState:UIControlStateNormal];
    
    //选中状态
    NSMutableDictionary *selectedText = [NSMutableDictionary dictionary];
    selectedText[NSForegroundColorAttributeName] = [UIColor orangeColor];
    [childViewController.tabBarItem setTitleTextAttributes:selectedText forState:UIControlStateSelected];
    
    //导航控制器
    NavigationViewController *navgationVC = [[NavigationViewController alloc]initWithRootViewController:childViewController];
    
    [self addChildViewController:navgationVC];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

/**
 *  addBtn 的代理方法
 *
 *  @param tabBar tabBar
 */
- (void)addBtnDidClick:(TabBar *)tabBar{
    
    MapViewController *addBtnVC = [[MapViewController alloc]init];
    addBtnVC.view.backgroundColor = [UIColor whiteColor];
    [self presentViewController:addBtnVC animated:YES completion:nil];
    
}

@end
